package com.situ.mall.controller.back;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.service.ICategoryService;
import com.situ.mall.util.JSONResult;

@Controller
@RequestMapping("/category")
public class CategoryController {
	@Autowired
	ICategoryService categoryService;
	
	@ResponseBody
	@RequestMapping("/selectByPage.action")
	public JSONResult selectByPage(Integer page, Integer limit, String name) {
		JSONResult jsonResult = categoryService.selectBypage(page, limit, name);
		return jsonResult;
	}
	
	@ResponseBody
	@RequestMapping("/deleteByPrimaryKey.action")
	public JSONResult delete(Integer id) {
		boolean isSuccess = categoryService.deleteByPrimaryKey(id);
		JSONResult jsonResult = null;
		if (isSuccess) {
			jsonResult = JSONResult.success("删除成功");
		} else {
			jsonResult = JSONResult.error("删除失败");
		}
		return jsonResult;
	}
	
	@ResponseBody
	@RequestMapping("/deleteAll.action")
	public JSONResult deleteAll(@RequestParam(value ="ids[]")Integer[] ids) {
		boolean isSuccess = categoryService.deleteAll(ids);
		JSONResult jsonResult = null;
		if (isSuccess) {
			jsonResult = JSONResult.success("删除成功");
		} else {
			jsonResult = JSONResult.error("删除失败");
		}
		return jsonResult;
	}
	
	@RequestMapping("/getCategoryListPage.action")
	public String getCategoryListPage() {
		return "back/category_list";
	}
	
	@RequestMapping("/getCategoryCountVO.action")
	public String getCategoryCountVO() {
		return "back/echarts";
	}
	
	@ResponseBody
	@RequestMapping("/selectCategoryCount.action")
	public JSONResult selectCategoryCount() {
		JSONResult jsonResult  = categoryService.selectCategoryCount();
		return jsonResult;
	}
}
